DATA ANALYSIS FROM SQLITEDATABASE —————————————

Author: Winfred Gatua —————————————————

Date:05/12/2022 ———————————————————

set working directory

setwd("~/OneDrive - University of Bristol/Winfred_PhDApps/Streamlit_MRevidenceentryapp/")
#install.packages('RSQLite')
#install.packages("forestly")
#devtools::install_github("elong0527/forestly")

library(RSQLite)
#library(dplyr)
library(ggplot2)
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(gridExtra)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.1     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ lubridate 1.9.2     ✔ tibble    3.2.1
## ✔ purrr     1.0.1     ✔ tidyr     1.3.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::combine() masks gridExtra::combine()
## ✖ dplyr::filter()  masks plotly::filter(), stats::filter()
## ✖ dplyr::lag()     masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(forestploter)
## 
## Attaching package: 'forestploter'
## 
## The following object is masked from 'package:plotly':
## 
##     add_text
library(grid)
library(stringr)

Connect to the database, read the tables, combine the data into a single dataframe

con <- dbConnect(SQLite(),'Mr_EvidenceDB')
#list tables
dbListTables(con) #list down the tables
## [1] "effectsizetype" "exposure"       "methods"        "outcome"       
## [5] "results"        "study"
result <- tbl(con, 'results')
results <- data.frame(result)
#exposure
exposure <- tbl(con, 'exposure')
exposure <- data.frame(exposure)
colnames(exposure) <- c("exposurename","exposureid")
exposure
##        exposurename exposureid
## 1               BMI         E1
## 2         Adiposity         E2
## 3               WHR         E3
## 4      childhoodBMI         E4
## 5          adultBMI         E5
## 6      fatmassindex         E6
## 7  fatfreemassindex         E7
## 8                FA         E8
## 9               UFA         E9
## 10          obesity        E10
## 11         bodyfat%        E11
## 12          BMIWGRS        E12
## 13           BMIGRS        E13
## 14             WHtR        E14
## 15              VAT        E15
#outcome
outcome <- tbl(con, 'outcome')
outcome <- data.frame(outcome)
colnames(outcome) <- c("outcomename","outcomeid") #rename the columns
outcome
##                   outcomename outcomeid
## 1       incident hypertension        O1
## 2           ever hypertension        O2
## 3                hypertension        O3
## 4    gestational hypertension        O4
## 5      essential hypertension        O5
## 6                         SBP        O6
## 7                         DBP        O7
## 8                         PAP        O8
## 9               PVremodelling        O9
## 10 Grade1diastolicdysfunction       O10
## 11      arterial hypertension       O11
#methods
methods <- tbl(con, 'methods')
methods <- data.frame(methods)
colnames(methods) <- c("methodname","methodid") #rename the columns
methods
##               methodname methodid
## 1                    IVW       M1
## 2              Wetmedian       M2
## 3                Wetmode       M3
## 4                MREgger       M4
## 5            IVestimator       M5
## 6                   MVMR       M6
## 7     penalisedwetmedian       M7
## 8  SIMEXcorrectedMREgger       M8
## 9                  MRGXE       M9
## 10                  TSLS      M10
## 11             MR-PRESSO      M11
#study
study <- tbl(con,'study')
study <- data.frame(study)
study
##        pmid
## 1  19470880
## 2  23824655
## 3  24462370
## 4  25411050
## 5  25712996
## 6  26568383
## 7  28196256
## 8  28317167
## 9  28678979
## 10 29935421
## 11 30045251
## 12 30462199
## 13 30707692
## 14 31195408
## 15 31501611
## 16 31708716
## 17 32636122
## 18 32665587
## 19 32712226
## 20 33045005
## 21 33131310
## 22 33323262
## 23 33771188
## 24 33980691
## 25 34001814
## 26 34002035
## 27 34120448
## 28 34322150
## 29 34333589
## 30 34465205
## 31 35074047
## 32 35186940
## 33 35232963
## 34 35599089
## 35 35656995
## 36 35694671
## 37 35947639
##                                                                                                                                                                    title
## 1                                                                                                  Does Greater Adiposity Increase Blood Pressure and Hypertension Risk?
## 2                                                                                    The Role of Adiposity in Cardiometabolic Traits: A Mendelian Randomization Analysis
## 3                                                             Causal Effects of Body Mass Index on Cardiometabolic Traits and Events: A Mendelian Randomization Analysis
## 4                                       Remnant cholesterol, low-density lipoprotein cholesterol, and blood pressure as mediators from obesity to ischemic heart disease
## 5                                                                                       Age- and Sex-Specific Causal Effects of Adiposity on Cardiovascular Risk Factors
## 6                                 MR-PheWAS: hypothesis prioritization among potential causal effects of body mass index on many outcomes, using Mendelian randomization
## 7                                                     Genetic Association of Waist-to-Hip Ratio With Cardiometabolic Traits, Type 2 Diabetes, and Coronary Heart Disease
## 8            Semiparametric methods for estimation of a nonlinear exposure-outcome relationship using instrumental variables with application to Mendelian randomization
## 9                                                         Association of Body Mass Index With Cardiometabolic Disease in the UK Biobank: A Mendelian Randomization Study
## 10                                                                                                Mendelian randomisation in type 2 diabetes and coronary artery disease
## 11                                                                        Causal association of body mass index with hypertension using a Mendelian randomization design
## 12                                                         Detecting and correcting for bias in Mendelian randomization analyses using Gene-by- Environment interactions
## 13                                         Searching for the causal effects of body mass index in over 300 000 participants in UK Biobank, using Mendelian randomization
## 14                                       Body mass index and body composition in relation to 14 cardiovascular conditions in UK Biobank: a Mendelian randomization study
## 15                                                               Contribution of genetics to visceral adiposity and its relation to cardiovascular and metabolic disease
## 16                                                                           On the Use of the Lasso for Instrumental Variables Estimation with Some Invalid Instruments
## 17                     Causal associations of body mass index and waist-to-hip ratio with cardiometabolic traits among Chinese children: A Mendelian randomization study
## 18                                 Avoiding dynastic, assortative mating, and population stratification biases in Mendelian randomization through within-family analyses
## 19                                               BMI Is Causally Associated With Pulmonary Artery Pressure But Not Hemodynamic Evidence of Pulmonary Vascular Remodeling
## 20                                                                    Novel loci for childhood body mass index and shared heritability with adult cardiometabolic traits
## 21                                                  Association of Cardiovascular Risk Factors and Lifestyle Behaviors With Hypertension A Mendelian Randomization Study
## 22                    A data-driven approach for studying the role of body mass in multiple diseases: a phenome-wide registry-based case-control study in the UK Biobank
## 23                      Phenome-wide investigation of the causal associations between childhood BMI and adult trait outcomes: a two-sample Mendelian randomization study
## 24                                  Genetic Evidence for Different Adiposity Phenotypes and Their Opposing Influences on Ectopic Fat and Risk of Cardiometabolic Disease
## 25                                                                             Birth weight, childhood obesity and risk of hypertension: a Mendelian randomization study
## 26                              Risk factors mediating the effect of body mass index and waist-to-hip ratio on cardiovascular outcomes: Mendelian randomization analysis
## 27                                              Causal Effect of Adiposity Measures on Blood Pressure Traits in 2 Urban Swedish Cohorts: A Mendelian Randomization Study
## 28                               A Novel Method for Mendelian Randomization Analyses With Pleiotropy and Linkage Disequilibrium in Genetic Variants From Individual Data
## 29                  Association between adiposity and cardiovascular outcomes: an umbrella review and meta-analysis of observational and Mendelian randomization studies
## 30 Mendelian Randomization Analyses Suggest Childhood Body Size Indirectly Influences End Points From Across the Cardiovascular Disease Spectrum Through Adult Body Size
## 31                                                   Disease consequences of higher adiposity uncoupled from its adverse metabolic effects using Mendelian randomisation
## 32                      Associations of Visceral Adipose Tissue, Circulating Protein Biomarkers, and Risk of Cardiovascular Diseases: A Mendelian Randomization Analysis
## 33                                         Robust Mendelian randomization in the presence of residual population stratification, batch effects and horizontal pleiotropy
## 34                                              Distinct causal effects of body fat distribution on cardiometabolic traits among children: Findings from the BCAMS study
## 35                                                            Genetic Determinants of Body Mass Index and Fasting Glucose Are Mediators of Grade 1 Diastolic Dysfunction
## 36                                                                      Genetically Predicted Obesity Causally Increased the Risk of Hypertension Disorders in Pregnancy
## 37                                                                Interaction-based Mendelian randomization with measured and unmeasured gene-by- covariate interactions
##    population    sex mean_age median_age lower_age upper_age    year samplesize
## 1         EUR   both     0.00       0.00         0      0.00 2009.00      37027
## 2         EUR   both     0.00       0.00         0      0.00 2013.00     198502
## 3         EUR   both     0.00       0.00         0      0.00 2014.00      34540
## 4         EUR   both     0.00       0.00         0      0.00 2015.00      65650
## 5         EUR   both     0.00       0.00         0     55.00 2014.97      67553
## 6         EUR   both     0.00       0.00         0      0.00 2015.00       8121
## 7         EUR female    57.00       0.00         0      0.00 2017.00     111986
## 8         EUR   both     0.00       0.00         0      0.00 2017.00     133687
## 9         EUR   both    56.87       0.00         0      0.00 2017.00     119859
## 10        EUR   both     0.00       0.00         0      0.00 2018.00          0
## 11     Korean   both     0.00       0.00        40     69.00 2018.00       8832
## 12        EUR   both     0.00       0.00         0      0.00 2018.00          0
## 13        EUR   both     0.00       0.00         0      0.00 2019.00     334968
## 14        EUR   both    57.20       0.00        40     68.96 2019.00     367703
## 15        EUR   both     0.00       0.00         0      0.00 2019.00          0
## 16        EUR   both     0.00       0.00         0      0.00 2018.00          0
## 17 East Asian   both     0.00       0.00         7     18.00 2020.00       2030
## 18        EUR   both     0.00       0.00         0      0.00 2020.00      61008
## 19        EUR   both     0.00       0.00         0      0.00 2021.00       1043
## 20        EUR   both     0.00       0.00         2      9.97 2020.00      61111
## 21        EUR   both     0.00       0.00         0      0.00 2020.00          0
## 22        EUR   both     0.00       0.00        37     73.00 2016.00     337536
## 23        EUR   both     0.00       0.00         2     10.00 2021.00          0
## 24        EUR   both     0.00       0.00         0      0.00 2021.00          0
## 25        EUR   both     0.00       0.00         0      0.00 2020.00          0
## 26        EUR   both     0.00       0.00         0      0.00 2021.00     898130
## 27        EUR   both     0.00       0.00         0      0.00 2021.00      27000
## 28        EUR   both     0.00       0.00         0      0.00 2021.00          0
## 29        EUR   both     0.00       0.00         0      0.00 2021.00          0
## 30        EUR   both     0.00       0.00         0      0.00 2021.00          0
## 31        EUR   both     0.00       0.00         0      0.00 2022.00          0
## 32        EUR   both     0.00       0.00         0      0.00 2022.00          0
## 33        EUR   both     0.00       0.00         0      0.00 2022.00          0
## 34 East Asian   both    12.41       0.00         0      0.00    0.00       3266
## 35        EUR   both    47.20      -0.03         0     60.00 2021.96       2440
## 36        EUR female     0.00       0.00         0      0.00 2022.00          0
## 37        EUR   both     0.00       0.00         0      0.00 2022.00     100000
##                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 author
## 1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    Nicholas J. Timpson, Roger Harbord, George Davey Smith, Jeppe Zacho, Anne Tybj√¶rg-Hansen, B√∏rge G. Nordestgaard
## 2                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            European Network for Genetic and Genomic Epidemiology (ENGAGE) consortium
## 3                                                                                                                                                                                            Michael V. Holmes,1,2,* Leslie A. Lange,3 Tom Palmer,4 Matthew B. Lanktree,5 Kari E. North,6 Berta Almoguera,7 Sarah Buxbaum,8 Hareesh R. Chandrupatla,7 Clara C. Elbers,9 Yiran Guo,7 Ron C. Hoogeveen,10 Jin Li,7 Yun R. Li,7 Daniel I. Swerdlow,2 Mary Cushman,11 Tom S. Price,12 Sean P. Curtis,13 Myriam Fornage,14 Hakon Hakonarson,7 Sanjay R. Patel,15 Susan Redline,15 David S. Siscovick,16 Michael Y. Tsai,17 James G. Wilson,18 Yvonne T. van der Schouw,19 Garret A. FitzGerald,12 Aroon D. Hingorani,2 Juan P. Casas,2,20 Paul I.W. de Bakker,19,21 Stephen S. Rich,22 Eric E. Schadt,23 Folkert W. Asselbergs,24,25,26 Alex P. Reiner,22,27 and Brendan J. Keating1,7,28,*
## 4                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               Anette Varbo  1 , Marianne Benn  1 , George Davey Smith  1 , Nicholas J Timpson  1 , Anne Tybjaerg-Hansen  1 , Børge G Nordestgaard  2
## 5                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          Tove Fall Engage Consortium
## 6                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     Louise A. C. Millard1,2, Neil M. Davies1, Nic J. Timpson1, Kate Tilling1, Peter A. Flach1,2 & George Davey Smith
## 7                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       Emdin CA, Khera AV, Natarajan P, Klarin D, Zekavat SM, Hsiao AJ, Kathiresan S.
## 8                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               James R Staley  1 , Stephen Burgess  1
## 9                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          Donald M. Lyall, PhD; Carlos Celis-Morales, PhD; Joey Ward, BSc; Stamatina Iliodromiti, MD;Jana J. Anderson, PhD; Jason M. R. Gill, PhD; Daniel J. Smith, PhD; Uduakobong Efanga Ntuk, PhD, MSc;Daniel F. Mackay, PhD; Michael V. Holmes, MD, PhD; Naveed Sattar, MD, PhD; Jill P. Pell, MD
## 10                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Timothy M Frayling  1 , Charli E Stoneman  1
## 11                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  Mee-Ri Lee, MD, PhDa, Youn-Hee Lim, PhDb,c, Yun-Chul Hong, MD, PhD
## 12                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              Wes Spiller,1* David Slichter,2 Jack Bowden1† and George Davey Smith
## 13                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    Louise A. C. MillardID1,2,3*, Neil M. DaviesID1,2, Kate TillingID1,2, Tom R. GauntID1,2, George Davey SmithID1,2
## 14                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     Susanna C. Larsson 1,2*, Magnus Ba Ãàck3,4, Jessica M.B. Rees 5,6, Amy M. Mason;Stephen Burgess
## 15                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            Torgny Karlsson  1 , Mathias Rask-Andersen  2 , Gang Pan  2 , Julia Höglund  2 , Claes Wadelius  2 , Weronica E Ek  2 , Åsa Johansson  3
## 16                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         Frank Windmeijer  1   2 , Helmut Farbmacher  3 , Neil Davies  2   4 , George Davey Smith  2
## 17                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         QiyingSongaTaoHuangbJieyunSongcXiangruiMengdChenxiongLiaYanWangaHaijunWanga
## 18 Ben Brumpton  1   2   3 , Eleanor Sanderson  4   5 , Karl Heilbron  6 , Fernando Pires Hartwig  4   7 , Sean Harrison  4   5 , Gunnhild Åberge Vie  8 , Yoonsu Cho  4   5 , Laura D Howe  4   5 , Amanda Hughes  4   5 , Dorret I Boomsma  9 , Alexandra Havdahl  4   10   11 , John Hopper  12 , Michael Neale  13 , Michel G Nivard  9 , Nancy L Pedersen  14 , Chandra A Reynolds  15 , Elliot M Tucker-Drob  16 , Andrew Grotzinger  16 , Laurence Howe  4   5 , Tim Morris  4   5 , Shuai Li  12   17 , Within-family Consortium; 23andMe Research Team; Adam Auton  6 , Frank Windmeijer  4   18 , Wei-Min Chen  19 , Johan Håkon Bjørngaard  8   20 , Kristian Hveem  8 , Cristen Willer  21   22   23 , David M Evans  4   24 , Jaakko Kaprio  25   26 , George Davey Smith #  4   5 , Bjørn Olav Åsvold #  8   27 , Gibran Hemani #  4   5 , Neil M Davies #  28   29   30
## 19                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   Timothy E. Thayer, MD; Rebecca T. Levinson, PhD; Shi Huang, PhD; Tufik Assad, MD; Eric Farber-Eger, BS; Quinn S. Wells, MD; Jonathan D. Mosley, MD, PhD; and Evan L. Brittain, MD
## 20                                                                                                                                                                                                                                                                                                                                           Suzanne Vogelezang1,2,3‡, Jonathan P. Bradfield4,5‡, Tarunveer S. Ahluwalia6,7,8,9, John A. Curtin10, Timo A. Lakka11,12,13, Niels Grarup8, Markus Scholz14,15, Peter J. van der Most16, Claire Monnereau1,2,3, Evie Stergiakouli17,18,19, Anni Heiskala20, Momoko Horikoshi21,22,23, Iryna O. Fedko24, Natalia Vilor-Tejedor25,26,27,28, Diana L. Cousminer29,30, Marie Standl31, Carol A. Wang32, Jorma Viikari33,34, Frank Geller35, Carmen  ́Iñiguez28,36,37, Niina Pitka ̈ nen38,39, Alessandra Chesi29, Jonas Bacelis40,41,
## 21                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Sabine van Oort , Joline W.J. Beulens, Adriana J. van Ballegooijen, Diederick E. Grobbee, Susanna C. Larsson
## 22                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       Elina Hyppönen  1 , Anwar Mulugeta  2 , Ang Zhou  3 , Vimaleswaran Karani Santhanakrishnan  4
## 23                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              Shan-Shan Dong1†, Kun Zhang1†, Yan Guo1, Jing-Miao Ding1, Yu Rong1, Jun-Cheng Feng1, Shi Yao1, Ruo-Han Hao1, Feng Jiang1, Jia-Bin Chen1, Hao Wu1, Xiao-Feng Chen1 and Tie-Lin Yang
## 24                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       Susan Martin  1 , Madeleine Cule  2 , Nicolas Basty  3 , Jessica Tyrrell  1 , Robin N Beaumont  1 , Andrew R Wood  1 , Timothy M Frayling  1 , Elena Sorokin  2 , Brandon Whitcher  3 , Yi Liu  2 , Jimmy D Bell  3 , E Louise Thomas  3 , Hanieh Yaghootkar 
## 25                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           Jingwen Fan  1 , Xuezhong Shi, Xiaocan Jia, Yuping Wang, Yang Zhao, Junzhe Bao, Haomin Zhang, Yongli Yang
## 26                                                                                                                                                                                                                                                                                                                                                                                                                                         Dipender Gill  1   2   3   4 , Verena Zuber  5   6   7 , Jesse Dawson  8 , Jonathan Pearson-Stuttard  5   7 , Alice R Carter  9   10 , Eleanor Sanderson  9   10 , Ville Karhunen  5 , Michael G Levin  11   12   13 , Robyn E Wootton  9   14   15 , Derek Klarin  16   17   18   19 , Philip S Tsao  20   21 , Konstantinos K Tsilidis  5   22 , Scott M Damrauer  13   23 , Stephen Burgess  6   24 , Paul Elliott  5   7   25   26   27
## 27                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     Alice Giontella  1   2 , Luca A Lotta  3 , John D Overton  3 , Aris Baras  3 , Regeneron Genetics Center; Pietro Minuz  1 , Olle Melander  2   4 , Dipender Gill  5   6 , Cristiano Fava  1   2
## 28                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 Yuquan Wang  1 , Tingting Li  1 , Liwan Fu  1 , Siqian Yang  1 , Yue-Qing Hu  1   2
## 29                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 Min Seo Kim  1   2 , Won Jun Kim  1   3 , Amit V Khera  4   5   6 , Jong Yeob Kim  7 , Dong Keon Yon  8 , Seung Won Lee  9 , Jae Il Shin  10 , Hong-Hee Won  2   11
## 30                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     Grace M Power  1 , Jessica Tyrrell  2 , Timothy M Frayling  2 , George Davey Smith  1 , Tom G Richardson  1   3
## 31                                                                                                                                                                                                                                                                                                Susan Martin  1 , Jessica Tyrrell  1 , E Louise Thomas  2 , Matthew J Bown  3   4 , Andrew R Wood  1 , Robin N Beaumont  1 , Lam C Tsoi  5 , Philip E Stuart  5 , James T Elder  5   6 , Philip Law  7 , Richard Houlston  7 , Christopher Kabrhel  8   9 , Nikos Papadimitriou  10 , Marc J Gunter  10 , Caroline J Bull  11   12   13 , Joshua A Bell  11   12 , Emma E Vincent  11   12   13 , Naveed Sattar  14 , Malcolm G Dunlop  15   16 , Ian P M Tomlinson  17 , Sara Lindström  18   19 , INVENT consortium; Jimmy D Bell  2 , Timothy M Frayling  1 , Hanieh Yaghootkar 
## 32                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              Yunying Huang  1 , Yaozhong Liu  1 , Yingxu Ma  1 , Tao Tu  1 , Na Liu  1 , Fan Bai  2 , Yichao Xiao  1 , Chan Liu  3 , Zhengang Hu  1 , Qiuzhen Lin  1 , Mohan Li  1 , Zuodong Ning  1 , Yong Zhou  1 , Xiquan Mao  1 , Qiming Liu  1
## 33                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Carlos Cinelli  1 , Nathan LaPierre  2 , Brian L Hill  2 , Sriram Sankararaman  2   3   4 , Eleazar Eskin  2   3   4
## 34                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      Liwan Fu  1 , Hong Cheng  2 , Xiaoyuan Zhao  2 , Dongqing Hou  2 , Xianghui Xie  3 , Jie Mi  4
## 35                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            Nataraja Sarma Vaitinadin , MBBS, PhD, MPH; Mingjian Shi , MD, PhD; Christian M. Shaffer, BS; Eric Farber-Eger , BS; Brandon D. Lowery, BS; Vineet Agrawal, MD, PhD; Deepak K. Gupta , MD, MSCI; Dan M. Roden , MD; Quinn S. Wells , MD, PharmD, MSCI, MSc; Jonathan D. Mosley , MD, PhD
## 36                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            Wenting Wang1,2†, Jiang-Shan Tan3†, Lu Hua3, Shengsong Zhu3, Hongyun Lin2, Yan Wu3* and Jinping Liu 
## 37                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          Wes Spiller  1 , Fernando Pires Hartwig  2 , Eleanor Sanderson  1 , George Davey Smith  1 , Jack Bowden  3
#effectsizetype
effectsizetype <- tbl(con,'effectsizetype')
effectsizetype <- data.frame(effectsizetype)
effectsizetype
##    id effectsizetype
## 1 ID1             OR
## 2 ID2             MD
## 3 ID3             HR
## 4 ID4           BETA
## 5 ID5 RiskDifference
#merging two dataframes results and exposure
results_exposure <- merge(results, exposure,by.x = "exposureid",by.y = "exposureid")
#merge the above dataframe and outcome
results_exposure_outcome <- merge(results_exposure,outcome, by.x = "outcomeid",by.y = "outcomeid")
#merge with study table
results_exposure_outcome_study <- merge(results_exposure_outcome,study, by.x = "pmid",by.y = "pmid")
#merge the above with methods 
results_exposure_outcome_study_method <- merge(results_exposure_outcome_study,methods, by.x = 'methodid',by.y='methodid')
#merge the above with effectsizetype table
results_exposure_outcome_study_method_effectsizetype <- merge(results_exposure_outcome_study_method, effectsizetype,by.x = 'effectsizetype_id',by.y = 'id')
#reorder the columns
colnames(results_exposure_outcome_study_method_effectsizetype)
##  [1] "effectsizetype_id" "methodid"          "pmid"             
##  [4] "outcomeid"         "exposureid"        "results_id"       
##  [7] "effectsize"        "lowerinterval"     "upperinterval"    
## [10] "pvalue"            "standard_error"    "strata"           
## [13] "exposurename"      "outcomename"       "title"            
## [16] "population"        "sex"               "mean_age"         
## [19] "median_age"        "lower_age"         "upper_age"        
## [22] "year"              "samplesize"        "author"           
## [25] "methodname"        "effectsizetype"
mydata <- results_exposure_outcome_study_method_effectsizetype[,c(3,6,15,24,22,16,23,17,18,19,20,21,
                                                   5,13,4,14,2,25,1,26,7,8,9,10,11,12)]

#Split the author column into two
mydata[c('first_author','last_author')] <- str_split_fixed(mydata$author,pattern = ',',2)
#combine pmid_first_author_exposure to be used as unique identifiers
mydata$UID <- paste(mydata$pmid,mydata$first_author,mydata$exposurename, sep = "_")
#mydata

#write out the data to a csv file
#write.table(mydata, file = "Obesity_HBP_MR_evidence.csv",sep = ",")

Mean difference (ID2)

####Looking at systolic blood pressure

#Systolic blood pressure----
mydata$effectsize[(mydata$effectsize==10.43)] <- 1.048
mydata$lowerinterval[(mydata$lowerinterval==4.82)] <- 0.482
mydata$upperinterval[(mydata$upperinterval==16.04)] <- 1.604

mydata$effectsize[(mydata$effectsize==3.85)] <- 0.385
mydata$lowerinterval[(mydata$lowerinterval==1.88)] <- 0.188
mydata$upperinterval[(mydata$upperinterval==5.79)] <- 0.579
#Diastolic blood pressure----
mydata$effectsize[(mydata$effectsize==2.97)] <- 0.297
mydata$lowerinterval[(mydata$lowerinterval==-0.08)] <- -0.008
mydata$upperinterval[(mydata$upperinterval==6.03)] <- 0.603

mydata$effectsize[(mydata$effectsize==1.79)] <- 0.179
mydata$lowerinterval[(mydata$lowerinterval==0.680)] <- 0.068
mydata$upperinterval[(mydata$upperinterval==2.90)] <- 0.290
#modify Louise Millard results
mydata$exposurename[mydata$exposurename == 'BMI' & mydata$effectsize == 0.29 & mydata$pmid == 26568383] <- "BMIscore32"

mydata$exposurename[mydata$exposurename == 'BMI' & mydata$effectsize == 0.385 & mydata$pmid == 26568383] <- 'BMIscoreFTO'

mydata$exposurename[mydata$exposurename == 'BMI' & mydata$effectsize == 0.305 & mydata$pmid == 26568383] <- "logBMIscore"

p1 <- mydata %>% 
  #group_by(pmid) %>% 
  filter(effectsizetype_id=="ID2" &outcomeid=="O6") %>% 
  ggplot(aes(y=UID,x=effectsize,xmin=lowerinterval,xmax=upperinterval)) +
  geom_point(aes(color=exposurename)) +
  geom_errorbarh(height=.2) +
  labs(title='Forest plot based on mean difference', x='Systolic blood pressure change in mmHg', y = 'StudyPMID_Author_exposure') +
  geom_vline(xintercept=0, color='black', linetype='dashed', alpha=.5) +
  facet_grid(outcomename ~ exposurename)+
  theme_classic()
ggplotly(p1)

Diastolic blood pressure

Mean difference for diastolic blood pressure

p2 <- mydata %>% 
  #group_by(pmid) %>% 
  filter(effectsizetype_id=="ID2" &outcomeid=="O7") %>% 
  ggplot(aes(y=UID,x=effectsize,xmin=lowerinterval,xmax=upperinterval)) +
  geom_point(aes(color=exposurename)) +
  geom_errorbarh(height=.2) +
  labs(title='Forest plot based on mean difference', x='Diastolic blood pressure change in mmHg', y = 'StudyPMID_Author_exposure') +
  geom_vline(xintercept=0, color='black', linetype='dashed', alpha=.5) +
  facet_grid(outcomename ~ exposurename)+
  theme_classic()
ggplotly(p2)

Risk difference(ID5)

Can we use risk difference when reporting results for continuous traits?

#Diastolic blood pressure----
P3 <- mydata %>% 
  #group_by(pmid) %>% 
  filter(effectsizetype_id=="ID5" & outcomeid=="O7") %>% 
  ggplot(aes(y=UID,x=effectsize,xmin=lowerinterval,xmax=upperinterval)) +
  geom_point(aes(color=outcomename)) +
  geom_errorbarh(height=.2) +
  labs(title='Forest plot based on risk difference', x='Risk difference', y = 'StudyPMID_Author_exposure') +
  geom_vline(xintercept=0, color='black', linetype='dashed', alpha=.5) +
  #facet_wrap(vars(outcomename))+
  theme_classic()
ggplotly(P3)

#Risk diference

#Hypertension----
#Rename the exposures
mydata$exposurename[mydata$exposurename == 'BMI' & mydata$effectsize == 0.83 & mydata$pmid == 32665587] <- "BMIsiblings"

mydata$exposurename[mydata$exposurename == 'BMI' & mydata$effectsize == 0.76 & mydata$pmid == 32665587] <- 'BMIsiblingsplitsample'
P4 <- mydata %>% 
  #group_by(pmid) %>% 
  filter(effectsizetype_id=="ID5" & outcomeid=="O3") %>% 
  ggplot(aes(y=UID,x=effectsize,xmin=lowerinterval,xmax=upperinterval)) +
  geom_point(aes(color=exposurename)) +
  geom_errorbarh(height=.2) +
  labs(title='Effect Size by study', x='Risk difference', y = 'StudyPMID_Author_exposure') +
  geom_vline(xintercept=0, color='black', linetype='dashed', alpha=.5) +
  facet_grid(exposurename ~ outcomename)+
  theme_classic()
ggplotly(P4)

#Beta estimates—-

#SBP----
P5 <- mydata %>% 
  #group_by(pmid) %>% 
  filter(effectsizetype_id=="ID4" & outcomeid== c("O6","O7") & population == 'EUR') %>% 
  ggplot(aes(y=UID,x=effectsize,xmin=lowerinterval,xmax=upperinterval)) +
  geom_point(aes(color=exposurename)) +
  geom_errorbarh(height=.2) +
  labs(title='Forest plot based on beta estimates', x='Beta', y = 'StudyPMID_Author_exposure') +
  geom_vline(xintercept=0, color='black', linetype='dashed', alpha=.5) +
  facet_grid(exposurename ~ outcomename)+
  theme_classic()
## Warning: There was 1 warning in `filter()`.
## ℹ In argument: `&...`.
## Caused by warning in `outcomeid == c("O6", "O7")`:
## ! longer object length is not a multiple of shorter object length
ggplotly(P5)
#DBP----
#Improve this plot
P6 <- mydata %>% 
  #group_by(pmid) %>% 
  filter(effectsizetype_id=="ID4" & outcomeid=="O7") %>% 
  ggplot(aes(y=UID,x=effectsize,xmin=lowerinterval,xmax=upperinterval)) +
  geom_point(aes(color=exposurename)) +
  geom_errorbarh(height=.2) +
  labs(title='Effect Size by study', x='Beta', y = 'StudyPMID_Author_exposure') +
  geom_vline(xintercept=0, color='black', linetype='dashed', alpha=.5) +
  #facet_wrap(vars(outcomename))+
  theme_classic()
ggplotly(P6)
#Pulmonary arterial hypertension----
class(results_exposure_outcome$standard_error)
## [1] "numeric"
P7 <- mydata %>% 
  #group_by(pmid) %>% 
  filter(effectsizetype_id=="ID4" & outcomeid=="O8") %>%
  ggplot(aes(y=UID,x=effectsize,xmin=lowerinterval,xmax=upperinterval))+
  geom_point(aes(color=exposurename)) +
  geom_errorbarh(height=.2) +
  labs(title='Forest plot based on beta estimates', x='Beta', y = 'StudyPMID_Author_exposure') +
  geom_vline(xintercept=0, color='black', linetype='dashed', alpha=.5) +
  #facet_wrap(vars(outcomename))+
  theme_classic()
ggplotly(P7)

#Odds ratios

#Hypertension----
class(mydata$standard_error)
## [1] "numeric"
P8 <- mydata %>% 
  #group_by(pmid) %>% 
  filter(effectsizetype_id=="ID1" & outcomeid=="O3") %>%
  ggplot(aes(y=UID,x=effectsize,xmin=lowerinterval,xmax=upperinterval))+
  geom_point(aes(color=exposurename)) +
  geom_errorbarh(height=.2) +
  labs(title='Forest plot based on odds ratios', x='Odds ratio', y = 'StudyPMID_Author_exposure') +
  geom_vline(xintercept=1, color='black', linetype='dashed', alpha=.5) +
  #facet_wrap(vars(outcomename))+
  theme_classic()
ggplotly(P8)
#SBP----
class(mydata$standard_error)
## [1] "numeric"
P9 <- mydata %>% 
  #group_by(pmid) %>% 
  filter(effectsizetype_id=="ID1" & outcomeid=="O6") %>%
  ggplot(aes(y=UID,x=effectsize,xmin=lowerinterval,xmax=upperinterval))+
  geom_point(aes(color=exposurename)) +
  geom_errorbarh(height=.2) +
  labs(title='Forest plot based on odds ratio', x='Odds ratio', y = 'StudyPMID_Author_exposure') +
  geom_vline(xintercept=1, color='black', linetype='dashed', alpha=.5) +
  facet_grid(exposurename ~ outcomename)+
  theme_classic()
ggplotly(P9)
#DBP----
class(results_exposure_outcome$standard_error)
## [1] "numeric"
P10 <- mydata %>% 
  #group_by(pmid) %>% 
  filter(effectsizetype_id=="ID1" & outcomeid=="O7") %>%
  ggplot(aes(y=UID,x=effectsize,xmin=lowerinterval,xmax=upperinterval))+
  geom_point(aes(color=methodname)) +
  geom_errorbarh(height=.2) +
  labs(title='Forest plot based on odds ratio', x='Odds ratio', y = 'StudyPMID_Author_exposure') +
  geom_vline(xintercept=1, color='black', linetype='dashed', alpha=.5) +
  facet_wrap(exposurename ~ methodname)+
  theme_classic()
ggplotly(P10)
#essentialhypertension----
class(results_exposure_outcome$standard_error)
## [1] "numeric"
P11 <- mydata %>% 
  #group_by(pmid) %>% 
  filter(effectsizetype_id=="ID1" & outcomeid=="O5") %>%
  ggplot(aes(y=UID,x=effectsize,xmin=lowerinterval,xmax=upperinterval))+
  geom_point(aes(color=methodname)) +
  geom_errorbarh(height=.2) +
  labs(title='Forest plot based on odds ratio', x='Odds ratio', y = 'Results_ID') +
  geom_vline(xintercept=1, color='black', linetype='dashed', alpha=.5) +
  facet_wrap(exposurename ~ methodname)+
  theme_classic()
ggplotly(P11)